package edu.jit.nsi.iot_ms.controller;

import edu.jit.nsi.iot_ms.domain.EnvThrsdCtlDO;
import edu.jit.nsi.iot_ms.domain.EnvTimeCtlDO;
import edu.jit.nsi.iot_ms.responseResult.result.ResponseResult;
import edu.jit.nsi.iot_ms.serviceimpl.custom.EnvThDefServiceImpl;
import edu.jit.nsi.iot_ms.serviceimpl.custom.EnvTmDefServiceImpl;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @packageName: com.jit.iot.jit.edu.nsi.controller
 * @className: EquipController
 * @Description:
 * @author: xxz
 * @date: 2019/7/30 19:27
 */

@Slf4j
@RestController
@RequestMapping(value = "/envctldef")
@Api(description = "自动控制参数管理")
@ResponseResult
public class EnvCtlController {
    @Resource
    EnvThDefServiceImpl envThDefService;

    @Resource
    EnvTmDefServiceImpl envTmDefService;


    //查询单元下的阈值自动控制参数
    @ApiOperation(value = "查询单元下的阈值自动控制参数" ,  notes="查询单元下的阈值自动控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/lstThCtlParam", method = RequestMethod.GET)
    public List<EnvThrsdCtlDO> lstThCtlParam(@ApiParam(name = "cell_id", value = "生产单元ID") @RequestParam("cell_id") int cell_id) {
        return envThDefService.lstThCtlParam(cell_id);
    }


    //查询单元下的时间自动控制参数
    @ApiOperation(value = "查询单元下的时间自动控制参数" ,  notes="查询单元下的时间自动控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/lstTmCtlParam", method = RequestMethod.GET)
    public List<EnvTimeCtlDO> lstTmCtlParam(@ApiParam(name = "cell_id", value = "生产单元ID") @RequestParam("cell_id") int cell_id) {
        return envTmDefService.lstTmCtlParam(cell_id);
    }

    //新增阈值自动环境控制
    @ApiOperation(value = "新增阈值自动环境控制" ,  notes="新增阈值自动环境控制")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/addThCtl", method = RequestMethod.POST)
    public EnvThrsdCtlDO addEnvCtl(
            @ApiParam(name = "cell_id", value = "生产单元ID") @RequestParam("cell_id") int cell_id,
            @ApiParam(name = "env_type", value = "被控环境参数") @RequestParam("env_type") String env_type,
            @ApiParam(name = "param_id", value = "参考环境参数id") @RequestParam("param_id") int param_id,
            @ApiParam(name = "auto_fg", value = "启用标识") @RequestParam("auto_fg") int auto_fg) throws Exception{
        return envThDefService.addThCtl(cell_id, env_type, param_id, auto_fg);
    }

    //新增时间自动环境控制
    @ApiOperation(value = "新增时间自动环境控制" ,  notes="新增时间自动环境控制")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/addTmCtl", method = RequestMethod.POST)
    public EnvTimeCtlDO addTmCtl(
            @ApiParam(name = "cell_id", value = "生产单元ID") @RequestParam("cell_id") int cell_id,
            @ApiParam(name = "env_type", value = "被控环境参数") @RequestParam("env_type") String env_type,
            @ApiParam(name = "time", value = "动作时间点") @RequestParam("time") String time,
            @ApiParam(name = "opt", value = "执行动作") @RequestParam("opt") int opt,
            @ApiParam(name = "auto_fg", value = "启用标识") @RequestParam("auto_fg") int auto_fg) throws Exception{
        return envTmDefService.addThCtl(cell_id, env_type, time,opt, auto_fg);
    }

    //更新阈值自动环境控制参数
    @ApiOperation(value = "更新阈值自动环境控制参数" ,  notes="更新阈值自动环境控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/updateThCtl", method = RequestMethod.POST)
    public boolean updateThCtl(
            @ApiParam(name = "id", value = "序列ID") @RequestParam("id") int id,
            @ApiParam(name = "env_type", value = "被控环境参数") @RequestParam("env_type") String env_type,
            @ApiParam(name = "param_id", value = "参考环境参数id") @RequestParam("param_id") int param_id,
            @ApiParam(name = "wnup", value = "告警上限", required = false) @RequestParam(value="wnup", required = false) float wnup,
            @ApiParam(name = "wndw", value = "告警下限", required = false) @RequestParam(value="wndw", required = false) float wndw,
            @ApiParam(name = "actup", value = "操作上限", required = false) @RequestParam(value="actup", required = false) float actup,
            @ApiParam(name = "actdw", value = "操作下限", required = false) @RequestParam(value="actdw", required = false) float actdw,
            @ApiParam(name = "autofg", value = "启用标识", required = false) @RequestParam(value="autofg", required = false) int autofg) throws Exception{
        return envThDefService.updateThCtl(id,  param_id, wnup, wndw, actup,actdw, autofg);
    }

    //更新时间自动环境控制参数
    @ApiOperation(value = "更新时间自动环境控制参数" ,  notes="更新时间自动环境控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/updateTmCtl", method = RequestMethod.POST)
    public boolean updateTmCtl(
            @ApiParam(name = "id", value = "序列ID") @RequestParam("id") int id,
            @ApiParam(name = "env_type", value = "被控环境参数") @RequestParam("env_type") String env_type,
            @ApiParam(name = "time", value = "动作时间点") @RequestParam("time") String time,
            @ApiParam(name = "opt", value = "执行动作") @RequestParam("opt") int opt,
            @ApiParam(name = "autofg", value = "启用标识", required = false) @RequestParam(value="autofg", required = false) int autofg) throws Exception{
        return envTmDefService.updateTmCtl(id,  env_type, time, opt, autofg);
    }

    //删除阈值环境控制参数
    @ApiOperation(value = "删除阈值环境控制参数" ,  notes="删除阈值环境控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/delThCtl", method = RequestMethod.DELETE)
    public boolean delThCtl(
            @ApiParam(name = "id", value = "序列ID") @RequestParam("id") int id)throws Exception{
        return envThDefService.delThCtl(id);
    }

    //删除时间环境控制参数
    @ApiOperation(value = "删除时间环境控制参数" ,  notes="删除时间环境控制参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "该参数值（value='Bearer {token}'）在request header中", paramType ="header", required = false, dataType = "String")
    })
    @RequestMapping(value = "/delTmCtl", method = RequestMethod.DELETE)
    public boolean delTmCtl(
            @ApiParam(name = "id", value = "序列ID") @RequestParam("id") int id)throws Exception{
        return envTmDefService.delTmCtl(id);
    }
}
